﻿using _2._16._2015_Blog.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace _2._16._2015_Blog.Controllers
{
    public class HomeController : Controller
    {
        #region Private Instance Class Variables/Fields

        private BlogDatabase _db;

        #endregion

        #region Constructors

        public HomeController()
        {
            _db = BlogDatabase.Instance;
        }

        #endregion

        #region Instance Methods (Actions)

        public ActionResult Index()
        {
            BlogListViewModel model = _db.GetBlogListViewModel();
       
            return View(model);
        }

        public ActionResult Details(int id)
        {
            BlogViewModel model = _db.GetBlogViewModel(id);

            return View(model);
        }

        [HttpPost]
        public ActionResult Details(BlogViewModel model)
        {
            BlogViewModel blog = _db.CreateComment(model.NewComment);

            return View(blog);
        }

        public ActionResult Create()
        {
            CreateBlogViewModel model = new CreateBlogViewModel();

            return View(model);
        }

        [HttpPost]
        public ActionResult Create(CreateBlogViewModel model)
        {
            _db.CreateBlogPost(model);

            return RedirectToAction("Index");
        }

        #endregion
    }
}